<!doctype html>
<html lang="zh-cn">
<head>

    <meta charset="utf-8">
    <meta name="generator" content="Hugo 0.57.2" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>SpringBoot | The Sky of OtsWang</title>
    <meta property="og:title" content="SpringBoot - The Sky of OtsWang">
    <meta property="og:type" content="article">
        
    <meta property="article:published_time" content="2019-04-28T15:35:54&#43;08:00">
        
        
    <meta property="article:modified_time" content="2019-04-28T15:35:54&#43;08:00">
        
    <meta name="Keywords" content="golang,go语言,otswang,java,博客,python">
    <meta name="description" content="SpringBoot">
        
    <meta name="author" content="OtsWang">
    <meta property="og:url" content="https://otswang.gitee.io/hugo/post/java/spring/springboot/">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">

    <link rel="stylesheet" href="/hugo/css/normalize.css">
    
        <link rel="stylesheet" href="/hugo/css/prism.css">
    
    <link rel="stylesheet" href="/hugo/css/style.css">
    <script type="text/javascript" src="//cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>

    


    
    
</head>

<body>
<header id="header" class="clearfix">
    <div class="container">
        <div class="col-group">
            <div class="site-name ">
                
                    <a id="logo" href="https://otswang.gitee.io/hugo/">
                        The Sky of OtsWang
                    </a>
                
                <p class="description">擅长写HelloWorld的小小码农</p>
            </div>
            <div>
                <nav id="nav-menu" class="clearfix">
                    
                    
                    <a  href="https://otswang.gitee.io/hugo/" title="Home">Home</a>
                    
                    <a  href="https://otswang.gitee.io/hugo/tags/" title="Tags">Tags</a>
                    
                    <a  href="https://otswang.gitee.io/hugo/categories/" title="Categories">Categories</a>
                    
                    <a  href="https://otswang.gitee.io/hugo/archives/" title="Archives">Archives</a>
                    
                    <a  href="https://otswang.gitee.io/hugo/about/" title="About">About</a>
                    
                </nav>
            </div>
        </div>
    </div>
</header>


<div id="body">
    <div class="container">
        <div class="col-group">

            <div class="col-8" id="main">
                <div class="res-cons">
                    <article class="post">
                        <header>
                            <h1 class="post-title">SpringBoot</h1>
                        </header>
                        <date class="post-meta meta-date">
                            2019年4月28日
                        </date>
                        
                        <div class="post-meta">
                            <span>|</span>
                            
                                <span class="meta-category"><a href="https://otswang.gitee.io/hugo/categories/java-spring">Java-Spring</a></span>
                            
                        </div>
                        
                        
                        
                        <div class="post-content">
                            <p>spring boot 日常记录</p>

<h2 id="为什么要用spring-boot">为什么要用spring boot</h2>

<p>Spring Boot 的开启注解是：@SpringBootApplication，其实它就是由下面三个注解组成的：</p>

<pre><code>@Configuration
@ComponentScan
@EnableAutoConfiguration
</code></pre>

<p>上面三个注解，前面两个都是 Spring 自带的，和 Spring Boot 无关，所以说上面的回答的不是在点上。
所以说 Spring Boot 最最核心的就是这个 <code>@EnableAutoConfiguration</code> 注解了，它能根据类路径下的 jar 包和配置动态加载配置和注入bean。</p>

<p>举个例子，比如我在 lib 下放一个 druid 连接池的 jar 包，然后在 application.yml 文件配置 druid 相关的参数，Spring Boot 就能够自动配置所有我们需要的东西，如果我把 jar 包拿掉或者把参数去掉，那 Spring Boot 就不会自动配置。</p>

<p>这样我们就能把许多功能做成公共的自动配置的启动器（starters），其实 druid 连接池就是这么做的，它提供了针对 Spring Boot 的启动器：druid-spring-boot-starter。</p>

<p>有了这个自动配置的启动器，我们就能非常简单的使用它，</p>

<pre><code>作者：穿格子衣上班
链接：https://juejin.im/post/5cc2c5fde51d453fdf6834b3
来源：掘金
著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。
</code></pre>

<h2 id="注解">注解</h2>

<p>@Value @ConfigurationProperties</p>

<pre><code class="language-java">@Component 
public class Person { 

@Value(&quot;i am name&quot;) 
private String name; 

} 

@Component 
@ConfigurationProperties(prefix = &quot;person&quot;) 
public class Person { 

private String name; 
private Integer age; 
private String sex; 

/**
 * person.name=kundy 
 * person.age=13 
 * person.sex=male 
 */

} 


</code></pre>

<p>value 的值：</p>

<ul>
<li>字面量</li>
<li>通过 ${key} 方式从环境变量中获取值</li>
<li>通过 ${key} 方式全局配置文件中获取</li>
<li>#{SpEL}</li>
</ul>

<h2 id="lombok-插件">lombok 插件</h2>

<p>@Data : 注解在类上, 为类提供读写属性, 此外还提供了 equals()、hashCode()、toString() 方法</p>

<p>@Getter/@Setter : 注解在类上, 为类提供读写属性</p>

<p>@ToString : 注解在类上, 为类提供 toString() 方法</p>

<p>@Slf4j : 注解在类上, 为类提供一个属性名为 log 的 log4j 的日志对象</p>

<p>@Log4j : 注解在类上, 为类提供一个属性名为 log 的 log4j 的日志对象</p>
                        </div>

                        


                        


                        <div class="post-meta meta-tags">
                            
                            <ul class="clearfix">
                                
                                <li><a href="https://otswang.gitee.io/hugo/tags/springboot">SpringBoot</a></li>
                                
                            </ul>
                            
                        </div>
                    </article>
                    
    

    
    
                </div>
            </div>
            <div id="secondary">

    <section class="widget">
        <form id="search" action="//www.google.com/search" method="get" accept-charset="utf-8" target="_blank" _lpchecked="1">
      
      <input type="text" name="q" maxlength="20" placeholder="Search">
      <input type="hidden" name="sitesearch" value="https://otswang.gitee.io/hugo/">
      <button type="submit" class="submit icon-search"></button>
</form>
    </section>

    
    <div class="clear">
        <div class="toc-article">
            <div class="toc-title">文章目录</dixsv>
            <nav id="TableOfContents">
<ul>
<li>
<ul>
<li><a href="#为什么要用spring-boot">为什么要用spring boot</a></li>
<li><a href="#注解">注解</a></li>
<li><a href="#lombok-插件">lombok 插件</a></li>
</ul></li>
</ul>
</nav>
        </div>
    </div>
    

</div>
        </div>
    </div>
</div>
<footer id="footer">
    <div class="container">
        &copy; 2020 <a href="https://otswang.gitee.io/hugo/">The Sky of OtsWang By OtsWang</a>.
        Powered by <a rel="nofollow noreferer noopener" href="https://gohugo.io" target="_blank">Hugo</a>.
        <a href="https://www.flysnow.org/" target="_blank">Theme</a> based on <a href="https://github.com/Dudiao137/maupassant-hugo" target="_blank">maupassant-ots</a>.
        
    </div>
</footer>


    <script type="text/javascript">
    
    (function(){
        $("pre code").parent().addClass("line-numbers")
    }())

    window.MathJax = {
        tex2jax: {
            inlineMath: [ ['$','$'] ],
            processEscapes: true
        }
    };
    </script>
    <script type="text/javascript" src="/hugo/js/prism.js" async="true"></script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML' async></script>

<a id="rocket" href="#top"></a>
<script type="text/javascript" src="/hugo/js/totop.js?v=0.0.0" async=""></script>







 
 <script src="https://mermaidjs.github.io/scripts/mermaid.min.js"></script>
 <script>
       mermaid.initialize({ startOnLoad: true });
 </script>
</body>
</html>
